home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / musik / MIDIFP21 / SOURCES / MY_LIB / SERVIMEM.C < prev   
Encoding:
C/C++ Source or Header  |  1996-08-23  |  1.4 KB  |  58 lines

  1. /**************************************************************
  2. *
  3. *                SERVIMEM.C
  4. *
  5. **************************************************************/
  6.  
  7. #include "servimem.pif"
  8.  
  9. #define max_bytes 4     /* a variable length number is composed of max.
  10.                            4 bytes, see the MIDI file specification */
  11.  
  12.  
  13. unsigned int read_var_len
  14. (
  15.     unsigned char *address ,
  16.     unsigned long *P_read_number ,
  17.     unsigned char *P_read_bytes 
  18. )
  19. {
  20. register unsigned long buffer = 0 ;
  21. register unsigned int errors = 0 ;
  22.  
  23.     *P_read_bytes = 0 ;
  24.     do
  25.     {
  26.         buffer = (buffer << 7) ;
  27.         (unsigned char)buffer = (unsigned char)buffer | (*address & 0x7f) ;
  28.         address ++ ; 
  29.         *P_read_bytes +=1 ;
  30.         if (*P_read_bytes > max_bytes) errors = -1 ;
  31.     } 
  32.     while ( (!errors) && (*(address-1) & 0x80) ) ;
  33.     *P_read_number = buffer ;
  34.     return(errors) ;
  35. }
  36.  
  37.  
  38. unsigned long read_long(unsigned char *address)
  39. {
  40. unsigned long buffer ;
  41.  
  42.     *((unsigned char *)&buffer    ) = *(address    ) ;
  43.     *((unsigned char *)&buffer + 1) = *(address + 1) ;
  44.     *((unsigned char *)&buffer + 2) = *(address + 2) ;
  45.     *((unsigned char *)&buffer + 3) = *(address + 3) ;
  46.     return(buffer) ;
  47. }
  48.  
  49.  
  50. unsigned int read_int(unsigned char *address)
  51. {
  52. unsigned int buffer ;
  53.  
  54.     *((unsigned char *)&buffer    ) = *(address    ) ;
  55.     *((unsigned char *)&buffer + 1) = *(address + 1) ;
  56.     return(buffer) ;
  57. }
  58.